home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / eflibpt4.zip / DEMO / DATATYPE / HASHCLST.PAS < prev    next >
Pascal/Delphi Source File  |  1996-08-18  |  2KB  |  51 lines

  1. { Borland Pascal Extended Function Library - EFLIB (C) Johan Larsson, 1996
  2.   Demonstration; hash table clustering test (tests algorithm effeciency)
  3.  
  4.   EFLIB IS PROTECTED BY THE COPYRIGHT LAW AND MAY NOT BE COPIED, SOLD OR
  5.   MANIPULATED. FOR MORE INFORMATION, SEE PROGRAM MANUAL! THIS DEMONSTRAT-
  6.   ION PROGRAM MAY FREELY BE USED AND DISTRIBUTED.                          }
  7.  
  8.  
  9. uses EFLIBDEF, EFLIBINI, EFLIBDAT, EFLIBBAS, EFLIBTXT;
  10.  
  11. const CapacityOfElements = 400; { Maximum capacity }
  12.       NumberOfElements   = CapacityOfElements div 4; { Number of elements to add }
  13.  
  14. var Table : HashTableObjectType; SomeData : string[30]; Index : word;
  15.  
  16.  
  17. begin
  18.      Randomize;
  19.  
  20.      with Table do begin
  21.           { Initializes hash table }
  22.           Initialize (CapacityOfElements, SizeOf(SomeData));
  23.  
  24.           { Add some random elements (the random elements will
  25.             all be of the same size and will result in ineffecient
  26.             use of the hashing algorithm, even though it has been
  27.             optimized for text elements). }
  28.  
  29.           for Index := 1 to NumberOfElements do begin
  30.               SomeData := StringGeneratedRandomly(Pred(SizeOf(SomeData)));
  31.               Add (SomeData); { Add some random strings }
  32.           end;
  33.  
  34.           { Show used elements }
  35.           for Index := 1 to Capacity do
  36.               if IsUsed(Index) then Write ('[x] ') else Write ('[ ] ');
  37.  
  38.           if Elements <> NumberOfElements then WriteLn ('Error - duplicate?');
  39.  
  40.           if (Search(ElementPointer(1)^) <> 1) then
  41.              WriteLn ('Test; first element doesn''t exist.');
  42.  
  43.           { EFLIB provides a very efficient hash code algorithm for
  44.             text strings that works bitwise. }
  45.  
  46.           WriteLn;
  47.  
  48.           Intercept;
  49.      end;
  50.      if GlobalDataError then WriteLn ('Error(s) reported!');
  51. end.